#!/usr/bin/env node

process.on("unhandledRejection", (error) => {
  console.error(error)
  process.exit(1)
})

const { run, test, expect, snapshot, info } = require("@xieyuheng/test-runner")
const changeCase = require("change-case")
const path = require("path")
const fs = require("fs")

let commands = {}

commands.t = async () => {
  await commands.test_all()
}

commands.test_all = async () => {
  await commands.test_lib()
  await commands.test_snapshot()
}

commands.test_lib = async () => {
  await test("node $file", { file: "lib/**/*.test.js" }, expect.ok)
}

commands.test_snapshot = async () => {
  await test(
    "node $file",
    { file: "lib/**/*.snapshot.js" },
    snapshot.out(({ file }) =>
      path.resolve("snapshot", changeCase.paramCase(file) + ".out")
    )
  )
}

info()

run(commands)
